package day08;
import java.util.HashSet;
import java.util.Random;
import java.util.Scanner;
import java.util.Set;

public class ball {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 用户输入篮球和红球号码  
        System.out.print("请输入1个篮球号码(1-6): ");
        int userBlueBall = scanner.nextInt();
        System.out.println("请输入6个红球号码(1-33), 使用空格分隔: ");
        String[] userRedBallsStr = scanner.nextLine().trim().split("\\s+");
        if (userRedBallsStr.length != 6) {
            System.out.println("请输入恰好6个红球号码!");
            return;
        }
        Set<Integer> userRedBalls = new HashSet<>();
        for (String redBallStr : userRedBallsStr) {
            int redBall = Integer.parseInt(redBallStr);
            if (redBall < 1 || redBall > 33) {
                System.out.println("红球号码必须在1到33之间!");
                return;
            }
            userRedBalls.add(redBall);
        }

        // 检查篮球是否在范围内  
        if (userBlueBall < 1 || userBlueBall > 6) {
            System.out.println("篮球号码必须在1到6之间!");
            return;
        }

        // 系统随机生成篮球和红球号码  
        Random random = new Random();
        int systemBlueBall = random.nextInt(6) + 1;
        Set<Integer> systemRedBalls = new HashSet<>();
        while (systemRedBalls.size() < 6) {
            int redBall = random.nextInt(33) + 1;
            systemRedBalls.add(redBall);
        }

        // 判断中奖的球数  
        int blueBallMatch = (userBlueBall == systemBlueBall) ? 1 : 0;
        int redBallMatches = 0;
        for (int redBall : systemRedBalls) {
            if (userRedBalls.contains(redBall)) {
                redBallMatches++;
            }
        }

        // 输出结果  
        System.out.println("您输入的篮球号码是: " + userBlueBall);
        System.out.println("您输入的红球号码是: " + userRedBalls);
        System.out.println("系统生成的篮球号码是: " + systemBlueBall);
        System.out.println("系统生成的红球号码是: " + systemRedBalls);
        System.out.println("您中了" + blueBallMatch + "个篮球和" + redBallMatches + "个红球。");
    }
}